import { createStore } from 'vuex'
import { reqMusicLyricInfo } from '@/api/item'
import user from './user'
import recommend from './recommend'
import rankinglist from './rankinglist'

export default createStore({
  actions: {
    //获取歌词
    async getMusicLyric({ commit }, value) {
      let result = await reqMusicLyricInfo(value)
      if (result.status == 200) {
        commit('MUSICLYRIC', result.data.lrc)
      }
    },
  },

  mutations: {
    //改变isBtnShow 显示/隐藏播放
    ISBTNSHOW(state, value) {
      state.isBtnShow = value;
    },
    //更新播放歌曲 切换歌曲
    UPDATEPLAYLIST(state, value) {
      state.playlist = value.list
      state.playlistIndex = value.index
    },
    //改变 detailShow 显示/隐藏歌曲详情页
    UPDATEDETAILSHOW(state, value) {
      state.detailShow = value
    },
    //保存歌词
    MUSICLYRIC(state, value) {
      state.lyricList = value || {}
    },
    //当前音乐播放时间点
    UPDATETIME(state, value) {
      state.currentTime = value
      // console.log(value);
    },
    //改变playlistIndex 切换上下首歌曲
    PREANDNEXTMUSICPLAY(state, value) {
      state.playlistIndex = value
    },
    //获取歌曲总时长
    GETDURATION(state, value) {
      state.duration = 0
      state.duration = value
      console.log(value);
    },
    //改变头部导航 显示/隐藏
    CHANGENAV(state, value) {
      state.isNav = value
    },

  },

  state: {
    playlist: [{
      al: {
        id: 137431418,
        name: "无名的人",
        pic: 109951166724351490,
        picUrl: "https://p2.music.126.net/tLKBLSGTBgHKpazu83hZfw==/109951166724351491.jpg",
        pic_str: "109951166724351491"
      }
      ,
      id: 1903149553,
      name: '无名的人',
      fee: 8
    }],
    playlistIndex: 0, //切换歌曲 索引
    isBtnShow: true,  // 播放/暂停按钮显示/隐藏
    detailShow: false, //歌曲详情页显示
    lyricList: {},    //歌词
    currentTime: 0,  //当前歌曲时间
    timer: 0,//获取curentTime定时器
    duration: 0, //歌曲总时长
    isNav: true, //是否显示头部导航

  },

  getters: {
  },

  modules: {
    user,
    recommend,
    rankinglist
  }
})
